﻿using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.WebControls;

namespace IMField
{
    // TODO: Replace, as needed, "SPFieldText" with some other class derived from SPField. 
    // TODO: Update, as needed, ParentType element in fldtypes*.xml in this solution. 
    [CLSCompliant(false)]
    [Guid("c1e4c593-0d39-428a-af1c-19dca4d2d1a6")]
    public class IMFieldField : SPFieldMultiColumn 
    {
        public IMFieldField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        {
        }
        
        public IMFieldField(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName)
        {
        }

        public override object GetFieldValue(string value)
        {
            if (string.IsNullOrEmpty(value))
                return null;
            SPFieldMultiColumnValue val = new SPFieldMultiColumnValue(value);            
            return val;
        }    
        public override BaseFieldControl FieldRenderingControl
        {
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            get
            {
                BaseFieldControl fieldControl = new IMFieldFieldControl();
                fieldControl.FieldName = this.InternalName;
                return fieldControl;
            }
        }
    }
}
